﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.EditPages
{
    public partial class LoanPhones : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            lstLoanPhone.OnNeedDataSource = lstLoanPhone_OnNeedDataSource;

            if (!IsPostBack)
            {
                lstLoanPhone.Refresh();
            }

            btnAddLoanPhone.Enabled = SessionUser.BranchID == Branches.CurrentBranchID && SessionUser.Admin;
            btnEditLoanPhone.Enabled = SessionUser.BranchID == Branches.CurrentBranchID && SessionUser.Admin;
            btnDeleteLoanPhone.Enabled = SessionUser.BranchID == Branches.CurrentBranchID && SessionUser.Admin;

            if (SessionUser.BranchID != Branches.CurrentBranchID || !SessionUser.Admin)
            {
                btnAddLoanPhone.OnClientClick = "";
                btnEditLoanPhone.OnClientClick = "";
                btnDeleteLoanPhone.OnClientClick = "";
            }
        }

        public string GetLoanPhoneEditPageLink()
        {
            return this.ResolveUrl("~/EditPages/EditLoanPhone.aspx?");
        }

        protected void lstLoanPhone_OnNeedDataSource(object sender, EventArgs e)
        {
            View_LoanPhones phones = new View_LoanPhones();
            string cols = "*";
            string sort = lstLoanPhone.SortExpression + " " + lstLoanPhone.SortDirection;
            int totalRow = phones.Search(View_LoanPhones.ColumnNames.BranchID + "=" + Branches.CurrentBranchID.ToString(), cols, sort.Trim(), lstLoanPhone.CurrentPageIndex * lstLoanPhone.PageSize, lstLoanPhone.PageSize);
            lstLoanPhone.VirtualItemCount = totalRow;
            lstLoanPhone.DataSource = phones.DefaultView;
        }

        protected void btnAddLoanPhone_OnClick(object sender, EventArgs e)
        {
            lstLoanPhone.Refresh();
        }

        protected void btnEditLoanPhone_OnClick(object sender, EventArgs e)
        {
            lstLoanPhone.Refresh();
        }

        protected void btnRemoveLoanPhone_OnClick(object sender, EventArgs e)
        {
            lstLoanPhone.DeleteCheckedItems();
            lstLoanPhone.Refresh();
        }
    }
}